#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;
void duplicateZeros(vector<int>& arr) {
    int None_num = 0, zero = 0;
    int cur = 0, dest = 0;
    for (auto& e : arr)
    {
        if (e != 0)  None_num++;
        else zero++;
        if (arr.size() - None_num - 2 * zero == 1)
        {
            dest = arr.size() - 2;
            arr[arr.size() - 1] = arr[None_num + zero];
            cur = None_num + zero - 1;
            break;
        }
        if (None_num + 2 * zero == arr.size())
        {
			cur = None_num + zero - 1;
			dest = arr.size() - 1;
            break;
        }
    }
    while (cur >= 0)
    {
        if (arr[cur] != 0)
        {
            arr[dest--] = arr[cur];
            cur--;
        }
        else
        {
            arr[dest--] = arr[cur];
            arr[dest--] = arr[cur];
            cur--;
        }
    }
}

int main()
{
	vector<int> arr = { 1,5,2,0,6,8,0,6,0 };
	duplicateZeros(arr);
	for (auto& e : arr)
	{
		cout << e << " ";
	}
	cout << endl;
	return 0;
}